using NL;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XGame
{
    public interface IMoveOfLevel
    {
        void Moving(Vector3 _dpos);
        void Restore();
    }
    public class MoveOfLevel : MonoBehaviour, IMoveOfLevel
    {
        public float FarIn = 1f;
        public void Moving(Vector3 _dpos)
        {
            transform.localPosition += _dpos * FarIn;
        }

        public void Restore()
        {
            transform.localPosition = _OldPos;
        }
        Vector3 _OldPos;
        // Start is called before the first frame update
        void Start()
        {
            _OldPos = transform.localPosition;
        }

    }
    public static class MoveOfLevelEX
    { 
        public static void  MOLMoving(this GameObject _who, Vector3 _dpos,float _life)
        {
            if (_who == null) return;

            IMoveOfLevel[] _moves = _who.GetComponentsInChildren<IMoveOfLevel>();
            if (_moves == null || _moves.Length < 1)
                return;

            _who.ADDLerp().Set(0, 1, _life).With((w,v)=>
            {
                foreach (var mv in _moves)
                    mv.Moving(_dpos);
            });


        }
        public static void MOLRestore(this GameObject _who, Vector3 _dpos)
        {
            if (_who == null) return;

            IMoveOfLevel[] _moves = _who.GetComponentsInChildren<IMoveOfLevel>();
            if (_moves == null || _moves.Length < 1)
                return;

            foreach (var mv in _moves)
                mv.Restore();
        }
    }
}

